from pydantic import BaseModel, Field
from datetime import datetime
from typing import List, Optional, Dict, Any


class QuestionRequest(BaseModel):
    question: str
    conversation_id: Optional[int] = None
    model_name: Optional[str] = None
    system_prompt_id: Optional[int] = Field(None, description="选用的系统提示词ID，仅新建会话时生效")
    kb_id: Optional[int] = Field(None, description="用于RAG召回的知识库ID")
    top_k: Optional[int] = Field(6, description="召回TopK")
    threshold: Optional[float] = Field(0.0, description="相似度阈值")
    include_citations: Optional[bool] = Field(True, description="是否返回引用信息供前端展示")


class ConversationResponse(BaseModel):
    conversation_id: int
    title: str
    start_time: datetime
    last_update_time: datetime
    model_name: str
    system_prompt_id: Optional[int] = None
    kb_id: Optional[int] = None


class MessageResponse(BaseModel):
    message_id: int
    sender_type: int
    content: str
    send_time: datetime
    sequence: int
    citations: Optional[List[Dict[str, Any]]] = None


class ConversationMessagesResponse(BaseModel):
    conversation_id: int
    messages: List[MessageResponse]


